*************************************************************************
* Replication Code for: "How Mechanization Shapes Coups"                *
* Ioannis Choulis, Marius Mehrl, Abel Escribà-Folch, and Tobias Böhmelt *
* Published in Comparative Political Studies                            *
*************************************************************************

* Code written and used in Stata 17.0 and R version 4.0.5. Unless noted otherwise, everything below is Stata code.

use "...\Mechanization Coup Replication Data\Mechanization_Coups_RepData.dta", clear

keep attempt success year abbrev ccode mech_ip mech milex effectivenumber pop campaign_navco conflict_ucdp polity2 gdp pop rgdpe pop_pwt milper_cow milper_WB banksindex intrastate interstate mid_dur mid_incid ideological interventionary positional spatial rivalry claim_chal claim_chaldur salchal claim_tgt claim_tgtdur saltgt govconflict terconflict govconflict_dur terconflict_dur govconflict_decay terconflict_decay mcw_imports mid_incid_chal mid_incid_tgt coup_elite coup_combat land i_share_armed gini_disp_av colruler numacad perdcls draft_binary alliance_number

label variable attempt "Coup Attempt"
label variable success "Successfull Coup"
label variable mech "Mechanization"
label variable mech_ip "Mechanization (Inter-polated)"
label variable intrastate "Intrastate Conflict"
label variable interstate "Interstate Conflict"
label variable numacad "Military Academies"
label variable perdcls "Military Periodicals"

****************************************************
* Last Variable constructions, log transformations *
****************************************************
gen ln_mech_ip=ln(mech_ip+1)
gen ln_mech=ln(mech+1)

gen ln_milex = ln(milex)
gen ln_effnumb=ln(effectivenumber)
gen ln_pop=ln(pop)

gen lag_campaign=l.campaign_navco 
gen lac_conflict=l.conflict_ucdp
 
gen regimetype=.
replace regimetype=0 if polity2<=6
replace regimetype=1 if polity2>-6 & polity2<6
replace regimetype=2 if polity2>=6 & polity2!=.
gen democ=0 if polity2!=.
replace democ=1 if regime==2
gen anoc=0  if polity2!=.
replace anoc=1 if regime==1

* For GDP p.c., we combine world bank and penn data to minimize missing values
gen gdp_pc_wb=gdp/pop
gen gdp_pc_pwt=rgdpe/pop_pwt
gen gdp_pc=gdp_pc_wb
replace gdp_pc=gdp_pc_pwt if gdp_pc_wb==.
pwcorr gdp_pc_wb gdp_pc_pwt gdp_pc
gen ln_gdp_pc=ln(gdp_pc)

gen diff_lngdppc=D.ln_gdp_pc
replace diff_lngdppc=0 if diff_lngdppc==.
gen diff_lnmilex=D.ln_milex
replace diff_lnmilex=0 if diff_lnmilex==.

* We combine military personnel measures from CoW (1979-2012) and World bank (2013-2018)
gen milper=milper_cow 
replace milper=milper_WB if milper_cow==.

* Construct Time since last coup attempt/success
btscs attempt year ccode, gen(att_years)
btscs success year ccode, gen(succ_years)


*****************
* Main Analysis *
*****************

* Figure 1
vioplot ln_mech_ip, over(attempt) scheme (plotplain) xlabel(1 "No Coup Attempt" 2 "Coup Attempt") ytitle("{it:Mechanization}") aspect(1)

* Table 1 (except for Area under PR Curve)
logit attempt ln_mech_ip c.att_years##c.att_years##c.att_years, vce(cluster ccode)
fitstat
lroc, nograph

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex c.att_years##c.att_years##c.att_years, vce(cluster ccode)
fitstat
lroc, nograph

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
fitstat
lroc, nograph

xtlogit attempt ln_mech_ip anoc democ ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict xb
roctab attempt xb
drop xb

logit attempt ln_mech i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
fitstat
lroc, nograph

* Figure 2
gen v2=ln_mech_ip
generate where = -0.0020
generate pipe = "|"

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
margins, at(ln_mech_ip=(0(0.2)3.8)) level(95) 
marginsplot, scheme(plotplain) xtitle("{it:Mechanization}") ytitle("Coup Attempt") recastci(rline) ciopts(lpattern(dash) lcolor(black)) plotopts(msymbol(none)) yline(0) name(g1, replace) aspect(1) title("") ///
addplot (scatter where v2 if e(sample),  ms(none) xlabel(0.0(0.5)4) ylabel(0.00(0.01)0.05) blcolor(gray) mlabel(pipe) mlabpos(0)) legend(off)
graph export g1.png, as(png) width(3609) height(2399) replace


* Area under the Precision Recall Curve for Table 1 
preserve 
logit attempt ln_mech_ip c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict phat0 if e(sample)
keep attempt phat0
drop if phat0==.
export delimited using "test0.csv", replace
restore

preserve 
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict phat1 if e(sample)
keep attempt phat1 
drop if phat1==.
export delimited using "test1.csv", replace
restore

preserve 
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict phat2 if e(sample)
keep attempt phat2 
drop if phat2==.
export delimited using "test2.csv", replace
restore

preserve 
xtlogit attempt ln_mech_ip anoc democ ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict phat2a if e(sample)
keep attempt phat2a 
drop if phat2a==.
export delimited using "test2a.csv", replace
restore

preserve 
logit attempt ln_mech i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict phat3 if e(sample)
keep attempt phat3 
drop if phat3==.
export delimited using "test3.csv", replace
restore

* Switch to R *
df0 <- read.csv(".../Mechanization Coup Replication Data/test0.csv")
df1 <- read.csv(".../Mechanization Coup Replication Data/test1.csv")
df2 <- read.csv(".../Mechanization Coup Replication Data/test2.csv")
df2a <- read.csv(".../Mechanization Coup Replication Data/test2a.csv")
df3 <- read.csv(".../Mechanization Coup Replication Data/test3.csv")

* If not previously installed: install.packages("PRROC")
library(PRROC)
fg0 <- df0$phat0[df0$attempt == 1]
bg0 <- df0$phat0[df0$attempt == 0]
roc0 <- roc.curve(scores.class0 = fg0, scores.class1 = bg0, curve = T)
plot(roc0)
pr0 <- pr.curve(scores.class0 = fg0, scores.class1 = bg0, curve = T)
plot(pr0)

fg1 <- df1$phat1[df1$attempt == 1]
bg1 <- df1$phat1[df1$attempt == 0]
roc1 <- roc.curve(scores.class0 = fg1, scores.class1 = bg1, curve = T)
plot(roc1)
pr1 <- pr.curve(scores.class0 = fg1, scores.class1 = bg1, curve = T)
plot(pr1)

fg2 <- df2$phat2[df2$attempt == 1]
bg2 <- df2$phat2[df2$attempt == 0]
roc2 <- roc.curve(scores.class0 = fg2, scores.class1 = bg2, curve = T)
plot(roc2)
pr2 <- pr.curve(scores.class0 = fg2, scores.class1 = bg2, curve = T)
plot(pr2)

fg2a <- df2a$phat2a[df2a$attempt == 1]
bg2a <- df2a$phat2a[df2a$attempt == 0]
roc2a <- roc.curve(scores.class0 = fg2a, scores.class1 = bg2a, curve = T)
plot(roc2a)
pr2a <- pr.curve(scores.class0 = fg2a, scores.class1 = bg2a, curve = T)
plot(pr2a)

fg3 <- df3$phat3[df3$attempt == 1]
bg3 <- df3$phat3[df3$attempt == 0]
roc3 <- roc.curve(scores.class0 = fg3, scores.class1 = bg3, curve = T)
plot(roc3)
pr3 <- pr.curve(scores.class0 = fg3, scores.class1 = bg3, curve = T)
plot(pr3)

* Table 2: 4-Fold Cross-Validation for Model 3
set seed 12345
* Full Model
forvalues h=1/10 {
preserve
quietly logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict fitted, pr
quietly roctab attempt fitted
xtile group=uniform(), nq(4)
generate cv_fitted=.
forvalues i=1/4 {
quietly logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years if group~=`i', vce(cluster ccode) 
quietly predict cv_fittedi, pr
quietly replace cv_fitted=cv_fittedi if group==`i'
quietly drop cv_fittedi
}
roctab attempt cv_fitted
capture drop fitted group1 cv_fitted
restore
}
* Drop Mechanization
forvalues h=1/10 {
preserve
quietly logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
keep if e(sample)
quietly logit attempt i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
predict fitted, pr
quietly roctab attempt fitted
xtile group=uniform(), nq(4)
generate cv_fitted=.
forvalues i=1/4 {
quietly logit attempt i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years if group~=`i', vce(cluster ccode)
quietly predict cv_fittedi, pr
quietly replace cv_fitted=cv_fittedi if group==`i'
quietly drop cv_fittedi
}
roctab attempt cv_fitted
capture drop fitted group cv_fitted
restore
}

***************************************
* Additional Analyses in the Appendix *
***************************************

* Table A1
logit attempt mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* Table A2
sum ln_mech_ip if e(sample), detail
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years if ln_mech_ip<=2.333645, vce(cluster ccode)

gen reduc_sample=1
replace reduc_sample=0 if ccode==2 | ccode==20 | (ccode>=200 & ccode<400)
replace reduc_sample=0 if ccode==900 | ccode==920
replace reduc_sample=0 if ccode==900 | ccode==920
replace reduc_sample=0 if ccode==740 | ccode==710
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years if reduc_sample==1, vce(cluster ccode)


* table A3
gen att_years2=att_years*att_years
gen att_years3=att_years*att_years2
firthlogit attempt ln_mech_ip democ anoc ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict att_years att_years2 att_years3


* table A4
heckprobit success ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.succ_years##c.succ_years##c.succ_years, select(attempt=ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years) vce(cluster ccode)


* table A5
logit attempt ln_mech_ip i.regime c.ln_effnumb##c.ln_effnumb ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A6
gen soldierqual=milper/milex
gen ln_personnel=ln(milper+1)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex ln_personnel diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex soldierqual diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A7
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex banksindex c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A8
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign intrastate interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A9
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l.intrastate l.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l2.intrastate l2.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l3.intrastate l3.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l4.intrastate l4.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l5.intrastate l5.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l6.intrastate l6.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l7.intrastate l7.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l8.intrastate l8.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l9.intrastate l9.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign l10.intrastate l10.interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A10
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign govconflict terconflict interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign govconflict_dur terconflict_dur interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign govconflict_decay terconflict_decay interstate c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A11
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign intrastate mid_dur c.att_years##c.att_years##c.att_years, vce(cluster ccode)  

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign intrastate mid_incid_chal mid_incid_tgt c.att_years##c.att_years##c.att_years, vce(cluster ccode)  


* table A12
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict rivalry c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict ideological interventionary positional spatial  c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A13
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict claim_chal claim_tgt c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict claim_chaldur claim_tgtdur c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict salchal saltgt c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* tab A14
gen ln_mcw_imports=ln(1+mcw_imports)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict ln_mcw_imports c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A15
logit attempt c.ln_mech_ip##i.democ ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A16
btscs coup_elite year ccode, gen(elite_years)
btscs coup_combat year ccode, gen(comb_years)

logit coup_elite ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.elite_years##c.elite_years##c.elite_years, vce(cluster ccode)

logit coup_combat ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.comb_years##c.comb_years##c.comb_years, vce(cluster ccode)


* table A17
reg3 attempt ln_mech_ip i.regime diff_lngdppc lag_campaign lac_conflict c.att_years##c.att_years##c.att_years (ln_mech_ip l.ln_mech_ip attempt ln_pop ln_gdp_pc ln_milex diff_lnmilex i.year)


* table A18
replace land=ln(land)
logit attempt ln_mech_ip land i_share_armed i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A19
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years i.year, vce(cluster ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years c.year##c.year##c.year, vce(cluster ccode)


* table A20
ipolate gini_disp_av year, gen(i_gini_disp_av) epolate by(ccode)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict i_gini_disp_av c.att_years##c.att_years##c.att_years, vce(cluster ccode)


* table A21
replace colruler=0 if (colruler!=200) & (colruler!=220)
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict i.colruler c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict numacad perdcls c.att_years##c.att_years##c.att_years, vce(cluster ccode)

logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict draft_binary c.att_years##c.att_years##c.att_years, vce(cluster ccode)

* table A22
logit attempt ln_mech_ip i.regime ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict alliance_number c.att_years##c.att_years##c.att_years, vce(cluster ccode)

* Figure A1
preserve
logit attempt ln_mech_ip anoc democ ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict c.att_years##c.att_years##c.att_years, vce(cluster ccode)
keep if e(sample)==1
keep attempt ln_mech_ip anoc democ ln_pop ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex lag_campaign lac_conflict att_years ccode
export delimited using "forest.csv", replace
restore


* Change to R
df2 <- read.csv(".../Mechanization Coup Replication Data/forest.csv")

#df2$regimetype <- as.factor(df2$regimetype)
df2$att_sq_years <- df2$att_years * df2$att_years
df2$att_cb_years <- df2$att_sq_years * df2$att_years

X <- cbind(df2$ln_mech_ip, df2$anoc, df2$democ, df2$ln_pop, df2$ln_gdp_pc, df2$ln_milex, 
           df2$diff_lngdppc,  df2$diff_lnmilex, df2$lag_campaign, df2$lac_conflict, 
           df2$att_years, df2$att_sq_years, df2$att_cb_years)

library(randomForest); set.seed(56768)
rf.model <- randomForest(y = as.factor(df2$attempt), x = X,
                         ntree = 100, localImp = TRUE, nodesize = 1, do.trace = TRUE, keep.forest = TRUE, keep.inbag=TRUE, proximity=TRUE)

rf.model
round(importance(rf.model), 2)
varImpPlot(rf.model, main = "", cex = 0.75, type = 1)

pdf(".../Mechanization Coup Replication Data/rf_evalMech.pdf", width = 8, height = 8)
varImpPlot(rf.model, main = "", cex = 0.75, type = 1, labels = "")
axis(2, at=seq(0.98,13,1),
     labels=rev(c("Coup Years²", "Pop.", "MilEx", "Coup Years", "Coup Years³", "GDP", "Mechanization", "Non-Violence", "Conflict", "Anocracy", "Democracy", "Change MilEx", "Change GDP")),
     pos=0.6, lwd=0, cex.axis=0.54, las=1)
dev.off()

